package com.hom.test;

import java.util.Scanner;

public class Exam3 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.println("请输入数字");
        int value = input.nextInt();
        System.out.println(value);

        int[] arr = {3,12,23,45,65};
        int index = -1;
        int left = 0;
        int right = arr.length -1;
        int mid = (left + right)/2;
        while(left<=right){
            if(value == arr[mid]){
                index = mid;
                break;
            }
            else if(value>arr[mid]){
                right= mid +1;
            }
            else if(value<arr[mid]){
                left = mid -1;
            }
            mid = (left + right)/2;
        }

        if(index==-1){
            System.out.println(value+"不存在");
        }else{
            System.out.println(value+"的下标是"+index);
        }
    }
}
